{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(6820, 22)\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "import pandas as pd\n",
    "\n",
    "# 设置文件夹路径\n",
    "folder_path = 'D:/个人爱好/十/227-旅游可视化/travel_ana_dis_system/app/static/spider/data/sight'  # 请将这里的your_folder_path_here替换成你的CSV文件所在的文件夹路径\n",
    "\n",
    "# 获取文件夹中的所有文件\n",
    "files = os.listdir(folder_path)\n",
    "\n",
    "# 初始化一个空的DataFrame列表\n",
    "dataframes = []\n",
    "\n",
    "# 遍历文件列表，找到所有的CSV文件\n",
    "for file in files:\n",
    "    if file.endswith('.csv'):\n",
    "        # 拼接文件路径\n",
    "        file_path = os.path.join(folder_path, file)\n",
    "        # 读取CSV文件，并追加到DataFrame列表中\n",
    "        dataframes.append(pd.read_csv(file_path))\n",
    "\n",
    "# 最后使用concat函数将所有的DataFrame拼接成一个大的DataFrame\n",
    "combined_df = pd.concat(dataframes, ignore_index=True)\n",
    "\n",
    "# 输出最终的DataFrame\n",
    "print(combined_df.shape)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['poiId', 'businessId', 'poiName', 'commentCount', 'commentScore',\n",
       "       'districtId', 'districtName', 'sightLevelStr', 'coverImageUrl',\n",
       "       'distanceStr', 'tagNameList', 'otherTag', 'detailUrl', 'price',\n",
       "       'priceTypeDesc', 'isFree', 'openStatus', 'shortFeatures',\n",
       "       'sightCategoryInfo', 'latitude', 'longitude', 'heatScore'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data =combined_df\n",
    "data.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count    6820.000000\n",
       "mean       52.859287\n",
       "std        85.089474\n",
       "min         0.000000\n",
       "25%         0.000000\n",
       "50%        30.000000\n",
       "75%        80.000000\n",
       "max      2780.000000\n",
       "Name: totalPrice1, dtype: float64"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data['price'].value_counts()\n",
    "temp = []\n",
    "for i in data['price']:\n",
    "    if i=='free':\n",
    "        temp.append(0)\n",
    "    else:\n",
    "        temp.append(float(i))\n",
    "data['totalPrice1']=temp\n",
    "data['totalPrice1'].describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [],
   "source": [
    "list_temp =[]\n",
    "for i in data['totalPrice1']:\n",
    "    if i <=5:\n",
    "        list_temp.append(\"低价\")\n",
    "    elif i >=5 and i<=50:\n",
    "        list_temp.append(\"高价\")\n",
    "    else :\n",
    "        list_temp.append(\"中价\")\n",
    "data['景点档次'] = list_temp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import folium #地图信息\n",
    "from folium.plugins import HeatMap\n",
    "import webbrowser #用于生成网页显示\n",
    "# 创建地图对象，设置中心点和缩放级别\n",
    "map = folium.Map(\n",
    "    # tiles=\"http://webrd02.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}\",  # 设置高德底图\n",
    "                   attr='default',location=[114.298569, 30.584354])\n",
    "# 根据小区档次设置不同的颜色\n",
    "colors = {'高价': 'red', '中价': 'blue', '低价': 'green'}\n",
    "# 遍历数据，添加标记\n",
    "for index, row in data.sample(500).iterrows():    \n",
    "    folium.Marker(location=[row['latitude'], row['longitude']],                  \n",
    "                  icon=folium.Icon(color=colors[row['景点档次']])).add_to(map)\n",
    "name = '分布1.html'\n",
    "map.save(name)  # 保存热力图文件\n",
    "# 将结果文件打开进行显示\n",
    "webbrowser.open(name, new=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取需要的数据\n",
    "lng = data['latitude']\n",
    "lat = data['longitude']\n",
    "heat_data = [[row['latitude'],row['longitude'],row['totalPrice1']] for index, row in data.iterrows()]\n",
    " \n",
    "# 绘制地图\n",
    "m = folium.Map(location=[114.298569,30.584354],\n",
    "               zoom_start=11,\n",
    "            #    tiles='https://wprd01.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1&scl=1&style=7',\n",
    "               attr='高德-常规图') # 初始化地图\n",
    " \n",
    "# 添加热力图层\n",
    "HeatMap(heat_data, name='热力图').add_to(m)\n",
    " \n",
    "# 保存地图\n",
    "m.save(r'分布2.html')\n",
    "webbrowser.open(r'分布2.html', new=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Chuandain latitude and longitude\n",
    "latitude =  30.584354 \n",
    "longitude = 114.298569\n",
    "\n",
    "# instantiate a feature group for the incidents in the dataframe\n",
    "incidents = folium.map.FeatureGroup()\n",
    "\n",
    "# read stations \n",
    "# cdata = pd.read_csv('StationInfo.csv')\n",
    "# for lat, lon,label  in zip(data.lat, data.lng, data.totalPrice1):\n",
    "#     incidents.add_child(\n",
    "#         folium.CircleMarker(\n",
    "#             [lat, lon],\n",
    "#             radius=7, \n",
    "#             color='yellow',\n",
    "#             fill=True,\n",
    "#             fill_color='red',\n",
    "#             fill_opacity=0.4,\n",
    "#             tooltip=label\n",
    "#         )\n",
    "#     )     \n",
    "# catalog heatmap\n",
    "heatdata =  data[['latitude','longitude','totalPrice1']].values.tolist()\n",
    "HeatMap(heatdata).add_to(incidents)\n",
    "\n",
    "\n",
    "# add a single earthquake\n",
    "incidents.add_child(folium.Marker([28.9, 103.3],icon=folium.Icon(color='red'), tooltip='M = 4.0'))\n",
    "\n",
    "# add area border\n",
    "# ls = folium.PolyLine(locations=[[22,98],[22,107],[34,107],[34,98],[22,98]],color='blue')\n",
    "# ls.add_to(incidents)\n",
    "\n",
    "# add incidents to map\n",
    "my_map = folium.Map(location=[latitude, longitude], zoom_start=6)\n",
    "my_map.add_child(incidents)\n",
    "\n",
    "# add latitude and longitude in the map when click\n",
    "my_map.add_child(folium.LatLngPopup())\n",
    "\n",
    "# save map\n",
    "my_map.save('分布3.html')\n",
    "webbrowser.open('分布3.html')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import folium\n",
    "import webbrowser\n",
    "\n",
    "# 获取需要的数据\n",
    "lng = data['longitude']\n",
    "lat = data['latitude']\n",
    "heat_data = [[row['latitude'], row['longitude'], row['totalPrice1']] for index, row in data.iterrows()]\n",
    "\n",
    "# 绘制地图\n",
    "m = folium.Map(location=[114.298569, 30.584354],\n",
    "               zoom_start=11,\n",
    "               tiles='https://wprd01.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1&scl=1&style=7',\n",
    "               attr='高德-常规图') # 初始化地图\n",
    "\n",
    "# 添加热力图层\n",
    "HeatMap(heat_data, name='热力图').add_to(m)\n",
    "\n",
    "# 添加卫星图层\n",
    "folium.TileLayer(\n",
    "    tiles='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',\n",
    "    attr='OpenStreetMap',\n",
    "    name='OpenStreetMap',\n",
    "    max_zoom=20,\n",
    "    subdomains=['a', 'b', 'c'],\n",
    "    overlay=False,\n",
    "    control=True\n",
    ").add_to(m)\n",
    "\n",
    "# 保存地图\n",
    "m.save(r'分布4.html')\n",
    "webbrowser.open(r'分布4.html', new=2)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv('D:/个人爱好/十/227-旅游可视化/travel_ana_dis_system/app/static/spider/data/ultimate_sight/ultimate_sight.csv', encoding='utf-8')\n",
    "df = df[df['sightLevelStr']=='5A']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
